﻿using PortableRiotGames.Infrastructure.Objects;
using System;
using System.Collections.Generic;

namespace PortableRiotGames.Infrastructure
{
    /// <summary>
    /// Base class for steam requests.
    /// </summary>
    public abstract class RequestBase
    {
        private string _key;

        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="key"></param>
        protected RequestBase(string key)
        {
            _key = key;
        }

        /// <summary>
        /// Region where to retrieve the data.
        /// </summary>
        public Region Region { get; set; }

        /// <summary>
        /// Base URL for RiotGames API.
        /// </summary>
        protected internal virtual string EndpointUrl
        {
            get { return string.Format("https://prod.api.pvp.net/api/lol/{0}/", this.Region.ToLowerString()); }
        }
        /// <summary>
        /// Supported regions for this request.
        /// </summary>
        protected internal abstract List<Region> SupportedRegions { get; }
        /// <summary>
        /// The complete URI of this request with parameters.
        /// </summary>
        /// <returns></returns>
        public Uri GetUri()
        {
            if (string.IsNullOrEmpty(_key))
            {
                throw new ArgumentNullException("Developer key cannot be null or empty.");
            }

            return new Uri(string.Format("{0}?api_key={1}&{2}", this.EndpointUrl, _key, this.GetParameterList().ToQueryString()));
        }

        /// <summary>
        /// List of parameters for this request object.
        /// </summary>
        /// <returns></returns>
        protected virtual QueryStringDictionary GetParameterList()
        {
            return new QueryStringDictionary();
        }
    }
}